package com.example.javabasic.other;

import java.io.*;

import static sun.java2d.cmm.ColorTransform.Out;

/**
 * @description 测试文件断点
 * @Author Lin FuYuan
 * @date 2021/2/22
 */
public class RandomFileTest {
    public static void main(String[] args) throws IOException {
        String file = "C:\\Users\\Administrator\\Desktop\\问题总结.txt";
        RandomAccessFile accessFile = new RandomAccessFile(new File(file),"r");
        String file2 = "C:\\Users\\Administrator\\Desktop\\问题总结2.txt";
        OutputStream out = new FileOutputStream(new File(file2));
        long start = 1;
        long end  = 100;
        accessFile.seek(start);
        byte[] b = new byte[10];
        int read = accessFile.read(b);
        start +=read;
        while(read!=-1&& start<end ){
            out.write(b,0,read);
            read = accessFile.read(b);
            start +=read;
        }
        accessFile.close();
        out.close();
    }
}
